import { ActionType, IState } from '../utils/types'
/**
 * 接收两个参数
 * 第一个参数是state
 * 第二个参数是action
 */
const initState: IState = {
  userInfo: {
    id: '',
    tel: '',
    name: '',
    desc: '',
    avatar: ''
  },
  currentOrg: ''
}
// reducer要接受action参数，然后进行逻辑处理，返回新的state
export const reducer = (state = initState, action: ActionType) => {
  switch (action.type) {
    case 'add_User':
      return {
        ...state,
        userInfo: { ...action.payload }
      }
    case 'set_current_org':
      return {
        ...state,
        currentOrg: action.payload
      }
    default:
      return state
  }
}
